#pragma strict

var buttonColorTo : Color32;
var buttonColorFrom : Color32;
var sliderText : TextMesh;
var colorSpeed : float;
var distPointA : float;
var distPointB : float;
var PointA : Transform;
var PointB : Transform;
var distValue : int;
var isDragging : boolean;
var distance : int;

function Start(){

	buttonColorTo = Color32(246,255,0,0);
	buttonColorFrom = Color32(150,150,150,0);	
	colorSpeed = 20;
	isDragging = false;
	distance = 5;
	
	renderer.material.SetColor("_Color", buttonColorFrom);

}

function Update() {

	var CameraOptions = GameObject.Find("Main Camera").GetComponent(MainCamera);
	
	distPointA = Vector3.Distance(PointA.transform.position, transform.position);
	distPointB = Vector3.Distance(PointB.transform.position, transform.position);
	
	Debug.Log("Distance from Point A: "+Mathf.Round(distPointA)+",Distance from Point B: "+Mathf.Round(distPointB));
	distValue = Mathf.Round(Mathf.Round((100 * distPointB)/(distPointB + distPointA)))/2;
	Debug.Log(distValue);
	
	sliderText.GetComponent(TextMesh).text = distValue.ToString();
	QualitySettings.shadowDistance = distValue;
	
	if(isDragging){
		transform.position.z = CameraOptions.toPoint.z;
		if(transform.position.z < PointB.transform.position.z){
			transform.position.z = PointB.transform.position.z;
		} else if(transform.position.z > PointA.transform.position.z){
			transform.position.z = PointA.transform.position.z;
		}
	}

}

function OnMouseEnter() {

	iTween.ColorTo(gameObject, buttonColorTo, colorSpeed * Time.deltaTime);

}

function OnMouseExit() {

	iTween.ColorTo(gameObject, buttonColorFrom, colorSpeed * Time.deltaTime);
	//isDragging = false;

}

function OnMouseDown() {

	isDragging = true;

}

function OnMouseUp() {

	isDragging = false;

}